<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('机构推送子任务列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <input type="hidden" name="infoId" th:value="${costomId}"/>
                        <li>
                            <label>任务描述：</label>
                            <input type="text" name="descInfo"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="special:itemInfo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary" onclick="batchEdit()">
                <i class="fa fa-edit"></i> 批量修改
            </a>
        </div>
        <input type="hidden" id="costomId" th:value="${costomId}"/>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('special:itemInfo:edit')}]];
    var addFlag = [[${@permission.hasPermi('special:itemInfo:add')}]];
    var changeStatus = [[${@permission.hasPermi('special:itemInfo:change')}]];
    var removeFlag = [[${@permission.hasPermi('special:itemInfo:remove')}]];
    var selectedIds = [costomId];

    var prefix = ctx + "special/itemInfo";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/" + $("#costomId").val(),
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/view/{id}",
            removeUrl: prefix + "/remove",
            modalName: "机构推送任务",
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    formatter: function (value, row, index) {
                        var result = '<span style="color: #1c84c6; border-bottom: 1px solid" onclick="countTotal(\'' + row.id + '\' , \'' + row.descInfo + '\' )">' + row.id + '</a>';
                        var modelType = row.modelType == 1 ? '竞价' : '分流';
                        result = result + '  [' + '<span style="color: blue;" >' + modelType + '</span>' + '] ';
                        return result;
                    }
                },
                {
                    field: 'priceAmount',
                    title: '价格'
                },
                {
                    field: 'descInfo',
                    title: '任务描述',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'starttime',
                    title: '推送时间',
                    formatter: function (value, row, index) {
                        return row.starttime + ' - ' + row.endtime;
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs " onclick="detailItemInfo(\'' + row.id + '\')"><i class="fa fa-street-view"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" onclick="copyItemInfo(\'' + row.id + '\')"><i class="fa fa-edit"></i>拷贝</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs" onclick="deleteItem(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a> ');

                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id  + '\',\'' + row.infoId  + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id  + '\',\'' + row.infoId  + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(id, infoId) {
        $.modal.confirm("确认要停用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id,"infoId": infoId ,"status": 0});
        })
    }

    /* 用户管理启用 */
    function enable(id, infoId) {
        $.modal.confirm("确认要启用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id,  "infoId": infoId ,"status": 1});
        })
    }

    function batchEdit() {
        var url = prefix + "/batchEdit/"+$("#costomId").val();
        $.modal.open('批量修改', url);
    }

    function copyItemInfo(itemId) {
        $.modal.openFull('拷贝推送任务', prefix + "/copy/" + itemId)
    }

    function detailItemInfo(itemId) {
        $.modal.openTab('查看任务详情', prefix + "/view/" + itemId)
    }

    function countTotal(itemId) {
        $.modal.openTab('推送统计', prefix + "/count/" + itemId)
    }

    function deleteItem(id) {
        // confirm before deleting item
        if (confirm("确定要删除吗？")) {
            $.ajax({
                url: prefix + "/remove",
                type: 'POST',
                data: {id: id, del_flag: 0},
                success: function (response) {
                    console.log(response);

                },
                error: function (error) {
                    console.log(error);
                }
            });
        }
    }
</script>
</body>
</html>